﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using LZ.DCode.Configuration;
using LZ.DCode.Web;

namespace LZ.DCode.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class DCodeDbContextFactory : IDesignTimeDbContextFactory<DCodeDbContext>
    {
        public DCodeDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<DCodeDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            DCodeDbContextConfigurer.Configure(builder, configuration.GetConnectionString(DCodeConsts.ConnectionStringName));

            return new DCodeDbContext(builder.Options);
        }
    }
}

